home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 36
/
Amiga Format CD36 (1999-01-22)(Future Publishing)(GB)[!][issue 1999-02].iso
/
-seriously_amiga-
/
misc
/
megabook
/
fileconv
/
source
/
fileconv_mb20.c
next >
Wrap
C/C++ Source or Header
|
1998-12-12
|
4KB
|
218 lines
/*
** MegaBook 2.0/2.1 -> 3.0 File Format converter
** By Tom Bampton
**
** © 1996 Eden Software
*/
#define Prototype extern
#include <exec/types.h>
#include <exec/memory.h>
#include <lists.h>
#include <dos/dos.h>
#include <intuition/intuition.h>
#include <libraries/reqtools.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>
#include <clib/reqtools_protos.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "fileio.h"
/* Globals */
struct rtFileRequester *filereq;
char filename[34];
struct EasyStruct req[]=
{
sizeof(struct EasyStruct),
0,
"MegaBook Critical Message",
" ",
"Ok"
};
/* Non-AutoOpened libs */
struct Library *ReqToolsBase;
/* Protos */
Prototype void Convert(char *file, char *to);
Prototype void showIMessage(char *text);
Prototype void init(void);
Prototype void showMessage(char *msg);
Prototype int request(char *msg, char *btn);
Prototype char * selectFile(char *title);
Prototype void doit(void);
void Convert(char *file, char *to)
{
struct MegaBookRec *rec;
struct MegaBookHead *head;
BPTR fp;
FILE *ip;
char buf[256];
if(head = AllocVec(sizeof(struct MegaBookHead), MEMF_CLEAR|MEMF_ANY|MEMF_PUBLIC))
{
if(rec = AllocVec(sizeof(struct MegaBookRec), MEMF_CLEAR|MEMF_ANY|MEMF_PUBLIC))
{
if(fp = Open(to, MODE_NEWFILE))
{
head->id = ID_HEAD;
head->records = 0;
Write(fp, head, sizeof(struct MegaBookHead));
rec->id = ID_RECORD;
if(ip = fopen(file, "r"))
{
fgets(buf, sizeof(buf), ip);
if(strcmp(buf, "PB20\n") == 0)
{
while(!feof(ip))
{
fgets(buf, sizeof(buf), ip);
if(feof(ip)) break;
buf[strlen(buf) - 1] = 0;
strcpy(rec->name, buf);
fgets(buf, sizeof(buf), ip);
buf[strlen(buf) - 1] = 0;
strcpy(rec->fone, buf);
fgets(buf, sizeof(buf), ip);
buf[strlen(buf) - 1] = 0;
strcpy(rec->fax, buf);
rec->cy1 = 0;
rec->cy2 = 1;
Write(fp, rec, sizeof(struct MegaBookRec));
head->records++;
}
Seek(fp, 0, OFFSET_BEGINING);
Write(fp, head, sizeof(struct MegaBookHead));
}
fclose(ip);
}
Close(fp);
}
FreeVec(rec);
}
FreeVec(head);
}
}
wbmain()
{
init();
}
main(int ac, char *av[])
{
if(ac >= 3)
Convert(av[1], av[2]);
else
init();
}
void init(void)
{
if(ReqToolsBase = OpenLibrary("reqtools.library", 38L))
{
if(filereq = rtAllocRequestA(RT_FILEREQ, NULL))
{
doit();
rtFreeRequest(filereq);
}
else showMessage("Couldn't allocate file requester");
CloseLibrary(ReqToolsBase);
}
else showIMessage("Couldn't open reqtools.library v38+");
}
void doit(void)
{
char *from, *to;
if(request("MegaBook v2.0/2.1 -> 3.0 File Converter\n"
"By Tom Bampton\n"
"\n"
"© 1996 Eden Sofware\n"
"\n"
"If you don't wish to continue, select quit.\n"
"\n"
"Other converters are available in the same\n"
"directory as this. If you can't find the\n"
"one you need, contact us and we'll write\n"
"the one you want.",
"_Continue|_Quit") == 0) return;
from = strdup(selectFile("Select file to convert..."));
if(from[0] == 0) return;
rtChangeReqAttr(filereq,
RTFI_MatchPat, "~(#?.info|.backdrop).mb",
TAG_END);
to = strdup(selectFile("Select file to save to..."));
if(to[0] == 0) return;
Convert(from, to);
}
/* Requester stuff */
void showIMessage(char *text)
{
req->es_TextFormat = text;
EasyRequest(NULL, req, NULL);
}
void showMessage(char *msg)
{
if(msg)
{
rtEZRequestTags(msg, "Oki", NULL, NULL,
RT_ReqPos, REQPOS_CENTERSCR,
RTEZ_ReqTitle, "FileConv Message",
// RTEZ_Flags, EZREQF_CENTERTEXT,
TAG_END);
}
}
int request(char *msg, char *btn)
{
int but;
but = rtEZRequestTags(msg, btn, NULL, NULL,
RT_ReqPos, REQPOS_CENTERSCR,
RT_Underscore, '_',
RTEZ_ReqTitle, "FileConv Request",
RTEZ_Flags, EZREQF_CENTERTEXT,
TAG_END);
return(but);
}
char * selectFile(char *title)
{
char buf[513];
if(rtFileRequest(filereq, filename, title,
RT_ReqPos, REQPOS_CENTERSCR,
RTFI_Flags, FREQF_PATGAD,
TAG_END))
{
strcpy(buf, filereq->Dir);
AddPart(buf, filename, sizeof(buf));
return(buf);
}
}